package com.lyp.qczp.contoller;

import java.util.List;

import javax.annotation.Resource;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lyp.qczp.entity.Node;
import com.lyp.qczp.service.MainService;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@CrossOrigin(origins = "*")
public class MainContrallor {
	@Resource
	private MainService mainService;
	
	/**
	 * 
	 * @param name
	 * @return
	 */
	@ApiOperation(value="模块查询", notes="根据名字查询所拥有的的模块")
	@ApiImplicitParam(name = "name", value = "姓名", required = true, dataType = "String", paramType = "path")
	
	@PostMapping("/testNode")
	public List<Node> testNode(String name) {
		List<Node> nodeTree = mainService.getNodeTree(name);
		return getChildrenNodeList(nodeTree,name);
		
	}
	@ApiIgnore
	public List<Node> getChildrenNodeList(List<Node> list,String name) {
		for (Node node : list) {
			List<Node> nextNodeTree = mainService.getNextNodeTree(node.getId(),name);
			if(nextNodeTree.isEmpty()) {
			}else {
				getChildrenNodeList(nextNodeTree,name);
				node.setChildren(nextNodeTree);
			}
		}
		return list;
	}
	@PostMapping("/testNode1")
	public List<Node> testNode1() {
		List<Node> nodeTree = mainService.getNodeTree1();
		
		return getChildrenNodeList1(nodeTree);
		
	}
	@ApiIgnore
	public List<Node> getChildrenNodeList1(List<Node> list) {
		for (Node node : list) {
			List<Node> nextNodeTree1 = mainService.getNextNodeTree1(node.getId());
			if(nextNodeTree1.isEmpty()) {
			}else {
				getChildrenNodeList1(nextNodeTree1);
				node.setChildren(nextNodeTree1);
			}
		}
		return list;
	}
	
}
